//
//  RegisterViewController.swift
//  ZTC_Final
//
//  Created by xy Man on 2022/5/25.
//

import UIKit

class RegisterViewController: UIViewController {

    @IBOutlet weak var loginName: UITextField!
    @IBOutlet weak var registerPassword: UITextField!
    
    @IBOutlet weak var status: UILabel!
    
    

    @IBAction func back2Login(_ sender: Any) {
        self.dismiss(animated: false)
    }
    
    @IBAction func registPressed(_ sender: Any) {
        // 判断输入框是否为空
        let name = loginName.text!
        let password = registerPassword.text!
        if name.count == 0 || password.count == 0{
            status.text = "请完整输入！"
            return
        }
        
        // 初始化数据库
        let sqlite = SQLiteManager.sharedInstance
        if !sqlite.openDB(){return}
        let testsql = "REPLACE INTO user VALUES('\(loginName.text!)', '\(registerPassword.text!)');"
        
        if !sqlite.execNoneQuerySQL(sql: testsql){sqlite.closeDB(); return}
        sqlite.closeDB()
        status.text = "注册成功"
//        testUserTable()
    }
    
//    func testUserTable()->Void{
//                // 初始化数据库
//                let sqlite = SQLiteManager.sharedInstance
//
//                if !sqlite.openDB(){return}
//                let testsql2 = "SELECT * FROM user"
//                if !sqlite.openDB(){return}
//                let query = sqlite.execQuerySQL(sql: testsql2)
//        sqlite.closeDB()
//                print(query)
//    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
